﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblKhuyenMaiDAO
    {
        private DBService _db = null;
        public TblKhuyenMaiDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable KhuyenMainInsUp(TblKhuyenMai km, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_TblKhuyenMai_InsUp",
                    new string[] { "@ID", "@TieuDe", "@TomTaNoiDung", "@NoiDung",  "@ImageURL", "@Mode" },
                    new object[] { km.ID, km.TieuDe, km.TomTatNoiDung, km.NoiDung, km.ImageURL, mode}, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetALL()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblKhuyenMai", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable Get_ByID(int ID)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from TblKhuyenMai where ID = @ID", new string[]{"@ID"}, new object[]{ID}, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetTopKM()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select top(1)* from TblKhuyenMai order by ID DESC", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
